﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
namespace GestorDeFlotasDesktop.Estadisticas
{
    public partial class Form1 : MasterPage 
    {
        ArrayList array = new ArrayList();
        Form ventanPadre;
        //int index;

        public Form1(Form ventanaParam)
        {
            InitializeComponent();
            ocultarMenu(ref ventanPadre, ventanaParam);
        }

        private void button3_Click(object sender, EventArgs e)
        {
            popUp(new AbmTarifa.AbmTarifa(this));
        }

        private void popUp(Form form) {
            form.Show();
                
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            cargarAnios();
        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            ventanPadre.Visible = true; 
        }

        private void btConsulta_Click(object sender, EventArgs e)
        {
            
           MessageBox.Show("Espere por favor...");
            if (chLIstTrimestre.Text == "" || ((!chbChoferMayor.Checked) && (!chbAutoMayor.Checked) && (!chbClienteMayor.Checked)) || cbAnio.Text == "")
                MessageBox.Show("Todos los campos de selección son obligatorios. Complete los campos que faltan");
            else
            {
                if (chbAutoMayor.Checked)
                {
                 if(chLIstTrimestre.GetItemChecked(0))
                    showForm(new MejoresAutos.MejoresAutos(this, 1, 3, Convert.ToInt32(cbAnio.SelectedItem)));
                if (chLIstTrimestre.GetItemChecked(1))
                    showForm(new MejoresAutos.MejoresAutos(this, 4, 6, Convert.ToInt32(cbAnio.SelectedItem)));
                if (chLIstTrimestre.GetItemChecked(2))
                    showForm(new MejoresAutos.MejoresAutos(this, 7, 9, Convert.ToInt32(cbAnio.SelectedItem)));
                if (chLIstTrimestre.GetItemChecked(3))
                    showForm(new MejoresAutos.MejoresAutos(this, 10, 12, Convert.ToInt32(cbAnio.SelectedItem)));

                    
                }
                if (chbChoferMayor.Checked)
                {
                    
                    if(chLIstTrimestre.GetItemChecked(0))
                         showForm(new MejoresChoferes.MejoresChoferes(this, 1, 3, Convert.ToInt32(cbAnio.SelectedItem)));
                    if (chLIstTrimestre.GetItemChecked(1))
                        showForm(new MejoresChoferes.MejoresChoferes(this, 4, 6, Convert.ToInt32(cbAnio.SelectedItem)));
                    if (chLIstTrimestre.GetItemChecked(2))
                        showForm(new MejoresChoferes.MejoresChoferes(this, 7, 9, Convert.ToInt32(cbAnio.SelectedItem)));
                    if (chLIstTrimestre.GetItemChecked(3))
                        showForm(new MejoresChoferes.MejoresChoferes(this, 10, 12, Convert.ToInt32(cbAnio.SelectedItem)));

                }
                if (chbClienteMayor.Checked)
                {
                    if (chLIstTrimestre.GetItemChecked(0))
                         showForm(new MejoresClientes.MejoresClientes(this, 1, 3, Convert.ToInt32(cbAnio.SelectedItem)));
                    if (chLIstTrimestre.GetItemChecked(1))
                        showForm(new MejoresClientes.MejoresClientes(this, 4, 6, Convert.ToInt32(cbAnio.SelectedItem)));
                    if (chLIstTrimestre.GetItemChecked(2))
                        showForm(new MejoresClientes.MejoresClientes(this, 7, 9, Convert.ToInt32(cbAnio.SelectedItem)));
                    if (chLIstTrimestre.GetItemChecked(3))
                        showForm(new MejoresClientes.MejoresClientes(this, 10, 12, Convert.ToInt32(cbAnio.SelectedItem)));

                }
            }

        }

        private void chLIstTrimestre_SelectedIndexChanged(object sender, EventArgs e)
        {
          
          

         
        }

        private void cbAnio_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void cbAnio_SelectedIndexChangedLeave(object sender, EventArgs e)
        {

        }
        

        private void cargarAnios() {

            
            int i=0;
            int anio = 2009;
            int aniofinal =Convert.ToInt32(DateTime.Now.Year);
            int distancia = aniofinal - anio;
            int[] anios = new int[distancia+1];
            for (i = 0; i <= distancia; i++)
            {
                anios[i] = anio;
                anio++;
            }

            cbAnio.MaximumSize = GetPreferredSize(new Size(121, distancia+1));
            cbAnio.DataSource = anios;
            cbAnio.Text = "";
        
        
        }

        private void chLIstTrimestre_SelectedIndexChanged_1(object sender, EventArgs e)
        {
            if (chLIstTrimestre.SelectedIndex != -1)
            {
                int i, index;
                index = chLIstTrimestre.SelectedIndex;
                for (i = 0; i < 4; i++)
                    if (i != index)
                        chLIstTrimestre.SetItemChecked(i, false);

                if (!chLIstTrimestre.GetItemChecked(index))
                    chLIstTrimestre.SetItemChecked(index, false);
                else
                    chLIstTrimestre.SetItemChecked(index, true);

                chLIstTrimestre.Refresh();
            }
            else {
                int i;
                for (i = 0; i < 4; i++)
                   
                        chLIstTrimestre.SetItemChecked(i, false);
            }

        }

        private void chbClienteMayor_CheckedChanged(object sender, EventArgs e)
        {
            if (chbClienteMayor.Checked) {

                chbChoferMayor.Checked = false;
                chbAutoMayor.Checked = false;
            }

        }

        private void chbChoferMayor_CheckedChanged(object sender, EventArgs e)
        {
            if (chbChoferMayor.Checked)
            {

                chbClienteMayor.Checked = false;
                chbAutoMayor.Checked = false;
            }

        }

        private void chbAutoMayor_CheckedChanged(object sender, EventArgs e)
        {
            if (chbAutoMayor.Checked)
            {

                chbClienteMayor.Checked = false;
                chbChoferMayor.Checked = false;
            }


        }

        private void button1_Click(object sender, EventArgs e)
        {
            chbClienteMayor.Checked = false;
            chbChoferMayor.Checked = false;
            chbAutoMayor.Checked = false;
            chLIstTrimestre.ClearSelected();
            cbAnio.Text = "";
        }

        
    }
}
